
import requests
import time

# POST 请求的数据
login_data = {
    'opr': 'pwdLogin',
    'userName': 'bean.wang@quectel.com',
    'pwd': '',
    'auth_tag': '',
    'rememberPwd': '1'
}

PASSWD = "xxxx"

def do_encrypt_rc4(data, key):
    """
    使用 RC4 算法对数据进行加密
    :param data: 要加密的数据
    :param key: 加密密钥
    :return: 加密后的数据（十六进制字符串）
    """
    key_length = len(key)
    data_length = len(data)

    key_array = [0] * 256
    sbox = [0] * 256

    for i in range(256):
        key_array[i] = ord(key[i % key_length])
        sbox[i] = i

    a = b = 0
    output = ''
    for i in range(data_length):
        a = (a + 1) % 256
        b = (b + sbox[a]) % 256
        sbox[a], sbox[b] = sbox[b], sbox[a]
        c = (sbox[a] + sbox[b]) % 256
        temp = ord(data[i]) ^ sbox[c]
        output += f'{temp:02x}'

    return output

def generate_pwd_auth_tag():
    """
    生成密码和认证标签
    """
    src = PASSWD
    timestamp = int(time.time())
    print(f"Current timestamp - auth_tag: {timestamp}")
    login_data['auth_tag'] = str(timestamp)

    key = str(timestamp)
    encrypted_pwd = do_encrypt_rc4(src, key)
    login_data['pwd'] = encrypted_pwd
    print(f"pwd: {encrypted_pwd}")

# 调用函数生成密码和认证标签
generate_pwd_auth_tag()

# 打印最终的登录数据
print(login_data)

